package prototype;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        List<Shape> list = new ArrayList<>();

        Circle circle = new Circle();
        circle.x = 10;
        circle.y = 20;
        circle.radius = 15;
        circle.color = "red";
        list.add(circle);

        Rectangle rectangle = new Rectangle();
        rectangle.x = 5;
        rectangle.y = 5;
        rectangle.width = 10;
        rectangle.height = 20;
        rectangle.color = "blue";
        list.add(rectangle);

        /**
         * 客户端 （Client） 可以复制实现了原型接口的任何对象
         */
        for (Shape shape : list) {
            Shape clone = shape.clone();
            System.out.println("before change color, clone color:" + clone.color);
            clone.color = "black";
            System.out.println("after change color, clone color:" + clone.color);
            System.out.println("after change color, shape color:" + shape.color);
            System.out.println("-----------------------------------------------");
        }
    }
}